package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.module.ADOrderModule;
import com.module.ADUserModule;

public class DoOrder extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String action=request.getParameter("action");
		ADOrderModule adOrderModule=new ADOrderModule();
		
		if(action.equals("update")){
			int sta=Integer.parseInt(request.getParameter("sta"));
			int orderid=Integer.parseInt(request.getParameter("orderid"));
			int flag;
			try {
				flag = adOrderModule.updateAction(sta, orderid);
				if(flag==1){
					response.sendRedirect("/CuitShopPlatform/admin/OrderManage.jsp");
				}
				else{
					System.out.print("error");
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		
		else if (action.equals("del")) {
			
			String id=request.getParameter("orderid");
			int orderid=Integer.parseInt(id);
			System.out.print(orderid);
			int flag;
			try {
				flag = adOrderModule.delAction(orderid);
				if(flag==1){
					response.sendRedirect("/CuitShopPlatform/admin/OrderManage.jsp");
				}
				else{
					System.out.print("error");
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		out.flush();
		out.close();
	}

}
